<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script
      crossorigin
      src="https://unpkg.com/react@18/umd/react.development.js"
    ></script>
    <script
      crossorigin
      src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
    ></script>
    <script
      crossorigin
      src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"
    ></script>
  </head>
  <body>
    <div id="root"></div>
  </body>
  <script type="text/babel">
    // const name = "孙悟空";
    // const lang = "zh";
    // let div;
    // if (lang == "en") {
    //   div = <div>hello {name}</div>;
    // } else {
    //   div = <div>你好 {name}</div>;
    // }
    // const Root = ReactDOM.createRoot(document.getElementById("root"));
    // Root.render(div);

    /**
     * 在JSX中会自动将数组中的元素在页面中显示
     */
    // const div = <div>{["第一个元素", "第二个元素", "第三个元素"]}</div>;
    // const Root = ReactDOM.createRoot(document.getElementById("root"));
    // Root.render(div);

    // 示例:渲染列表
    const data = ["孙悟空", "猪八戒", "沙和尚"];
    // // arr = [<li>孙悟空</li>,<li>猪八戒</li>,<li>沙和尚</li>]

    // 方法一:
    // const arr = [];
    // for (let i = 0; i < data.length; i++) {
    //   arr.push(<li>{data[i]}</li>);
    // }
    // console.log(arr);
    // const list = <ul>{arr}</ul>;

    // 方法二:
    // const arr = data.map((item) => <li>{item}</li>);
    // const list = <ul>{arr}</ul>;

    // 方法三:
    const list = (
      <ul>
        {data.map((item) => (
          <li>{item}</li>
        ))}
      </ul>
    );

    const Root = ReactDOM.createRoot(document.getElementById("root"));
    Root.render(list);
  </script>
</html>
